// 1 引入Vuex
import vuex from "vuex"

//引入 Vue
import Vue from "vue"

// vuex实际上是Vue的插件
Vue.use(vuex)

const mutations={
    increment(state){
        state.count++
    },
    decrement(state){
        state.count--
    },
    incrementN(state,{n}){
        state.count+=n
    }
}
const actions={
    incrementWait({commit}){
        setTimeout(() => {
            commit('increment')
        }, 2000);
    }
}

const getters={
    add(state){
        return state.count+"hahahah"
    }
}

//创建store
//暴露store给入口文件

export default new vuex.Store({
    state:{
        count:1
    },
    mutations,
    actions,
    getters
})

